public class Problem {
    int answer=-2;
    Point head;

    public void createNoLoopProblem(int length) {
        if (length == 0) {
            return;
        }

        this.head = new Point();
        Point first = head;
        for (int i = 1; i < length; i++) {
            Point second = new Point();
            first.next = second;
            first = second;
        }
        this.answer = -1;
    }

    public void createLoopProblem(int length, int before) {
        if (length==0 || length<=before) return;

        this.head = new Point();
        //System.out.println("before: " + before + " length: " + length);

        Point first = head;
        for (int i = 1; i < before; i++) {
            Point second = new Point();
            first.next = second;
            first = second;
        }
        Point headLoop;
        if (before != 0) {
            headLoop = new Point();
            first.next = headLoop;
            this.answer = headLoop.value;
            first = headLoop;
        } else {
            headLoop = head;
            this.answer = head.value;
        }
        for (int i = 1; i < (length - before); i++) {
            Point second = new Point();
            first.next = second;
            first = second;
        }
        first.next = headLoop;
    }

    public Problem() {
        int length = Main.r.nextInt(30000)+1;
        if (Main.r.nextBoolean()) {
            createNoLoopProblem(length);
        } else {
            createLoopProblem(length,Main.r.nextInt(length));
        }
    }

    public Problem(int length) {
        createNoLoopProblem(length);
    }
    public Problem(int length,int before) {
        createLoopProblem(length,before);
    }
}
